package com.geekband.Test01.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.geekband.Test01.R;
import com.geekband.Test01.UserInfo;

import java.util.List;

/**
 * Function:
 * Create date on 15/11/4.
 *
 * @author Conquer
 * @version 1.0
 */
public class TestAdapter extends BaseAdapter {

    private Context mContext;
    private List<UserInfo> mUserInfos;
    private LayoutInflater mLayoutInflater;

    public TestAdapter(Context context, List<UserInfo> userInfos) {
        mContext = context;
        mUserInfos = userInfos;
        // 三种获取mLayoutInflater的方式
        mLayoutInflater = ((Activity) mContext).getLayoutInflater();
        mLayoutInflater = LayoutInflater.from(mContext);
        mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }


    @Override
    public int getCount() {
        return mUserInfos.size();
    }

    @Override
    public Object getItem(int position) {
        return mUserInfos.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemViewType(int position) {

        return super.getItemViewType(position);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = mLayoutInflater.inflate(R.layout.item_phone_book_friend, null);
            viewHolder = new ViewHolder();

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.mTextView = (TextView) convertView.findViewById(R.id.name_text_view);
        viewHolder.mTextView.setText(mUserInfos.get(position).getUserName());

        return convertView;
    }

    class ViewHolder {
        TextView mTextView;
    }
}
